package com.person.ntv.shiro.filter;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.web.filter.PathMatchingFilter;
import org.springframework.beans.factory.annotation.Autowired;

import com.person.Constants;
import com.person.ntv.entity.sys.SysUser;
import com.person.ntv.service.sys.SysUserService;

public class SysUserFilter extends PathMatchingFilter {
	  @Autowired
	    private SysUserService sysUserService;
	    @Override
	    protected boolean onPreHandle(ServletRequest request, ServletResponse response, Object mappedValue) throws Exception {
	    	 
	    	if(request instanceof HttpServletRequest){
        		if(((HttpServletRequest)request).getSession().getAttribute(Constants.CURRENT_USER)==null){
        		SysUser user = (SysUser)SecurityUtils.getSubject().getPrincipal();
        		((HttpServletRequest)request).getSession().setAttribute(Constants.CURRENT_USER,user);
        		}
        	}
	    	return true;
	    }
}
